define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'lejia/weixingongzhonghao/index' + location.search,
                    add_url: 'lejia/weixingongzhonghao/add',
                    edit_url: 'lejia/weixingongzhonghao/edit',
                    del_url: 'lejia/weixingongzhonghao/del',
                    multi_url: 'lejia/weixingongzhonghao/multi',
                    table: 'wx_config',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'wechat_id',
                sortName: 'wechat_id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'wechat_id', title: __('Wechat_id')},
                        {field: 'wx_name', title: __('Wx_name')},
                        {field: 'appid', title: __('Appid')},
                        {field: 'appsecret', title: __('Appsecret')},
                        {field: 'encodingaeskey', title: __('Encodingaeskey')},
                        {field: 'token', title: __('Token')},
                        {field: 'qr_url', title: __('Qr_url'), formatter: Table.api.formatter.url},
                        {field: 'user_name', title: __('User_name')},
                        {field: 'service_type_info', title: __('Service_type_info')},
                        {field: 'verify_type_info', title: __('Verify_type_info')},
                        {field: 'type', title: __('Type')},
                        {field: 'ctime', title: __('Ctime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'exp_time', title: __('Exp_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'share_title', title: __('Share_title')},
                        {field: 'share_imgurl', title: __('Share_imgurl'), formatter: Table.api.formatter.url},
                        {field: 'share_desc', title: __('Share_desc')},
                        {field: 'isgetuserinfo', title: __('Isgetuserinfo')},
                        {field: 'vender1', title: __('Vender1')},
                        {field: 'vender2', title: __('Vender2')},
                        {field: 'vender3', title: __('Vender3')},
                        {field: 'authorizer_access_token', title: __('Authorizer_access_token')},
                        {field: 'expires_in', title: __('Expires_in')},
                        {field: 'authorizer_refresh_token', title: __('Authorizer_refresh_token')},
                        {field: 'principal_name', title: __('Principal_name')},
                        {field: 'business_info', title: __('Business_info')},
                        {field: 'func_info', title: __('Func_info')},
                        {field: 'authorizer_func_info', title: __('Authorizer_func_info')},
                        {field: 'head_img', title: __('Head_img')},
                        {field: 'auth_status', title: __('Auth_status')},
                        {field: 'status', title: __('Status')},
                        {field: 'mp_verified', title: __('Mp_verified')},
                        {field: 'auth_url', title: __('Auth_url'), formatter: Table.api.formatter.url},
                        {field: 'push_flag', title: __('Push_flag'), formatter: Table.api.formatter.flag},
                        {field: 'push_data_url', title: __('Push_data_url'), formatter: Table.api.formatter.url},
                        {field: 'template_id', title: __('Template_id')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});